package xiancheng.demo03;

/**
 * @author Mr.ma
 * @since 2022/10/31 14:02
 *
 * 多线程卖票
 **/
public class Test03 {
    public static void main(String[] args) {
        Sale sale = new Sale();
        Thread thread01 = new Thread(sale);
        thread01.setName("窗口1");
        Thread thread02 = new Thread(sale);
        thread02.setName("窗口2");
        Thread thread03 = new Thread(sale);
        thread03.setName("窗口3");
        Thread thread04 = new Thread(sale);
        thread04.setName("窗口4");
        thread01.start();
        thread02.start();
        thread03.start();
        thread04.start();
    }
}
class Sale implements Runnable{
    private int ticket = 100;
    @Override
    public void run() {
       while(true){
           if (ticket > 0){
               System.out.println(Thread.currentThread().getName() + "卖了一张票，还剩" + --ticket +"张票");
           } else {
               System.out.println("票买完了");
               break;
           }
       }
    }
}